﻿Imports BUS
Imports DAO
Imports DTO


Public Class FormTraCuuSach
    Private sach As Sach_CRT

    Private Sub FormTraCuuSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadTheLoai()
        ComboBoxTheLoai.SelectedIndex = -1
        sach = New Sach_CRT()
        CapNhatTieuChuanTraCuu()
        Dim dts As New DataTable()
        dgvKQTraCuu.DataSource = dts

    End Sub

    Public Sub LoadTheLoai()
        Dim dt As New DataTable
        dt = TheLoai_BUS.LoadTheLoai()
        ComboBoxTheLoai.DataSource = dt
        ComboBoxTheLoai.DisplayMember = "TenTheLoai"
        ComboBoxTheLoai.ValueMember = "MaTheLoai"
    End Sub

    Private Sub ButtonThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonThoat.Click
        Me.Close()
    End Sub

    Private Sub CapNhatTieuChuanTraCuu()
        sach.Ten = txtTen.Text
        sach.TacGia = txtTacGia.Text
        sach.MaTheLoai = ComboBoxTheLoai.SelectedValue
    End Sub

    Private Sub ButtonTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTraCuu.Click

        CapNhatTieuChuanTraCuu()
        Dim SachBus As New Sach_BUS()
        Dim dts As DataTable
        dts = SachBus.TraCuuSach(sach)
        dgvKQTraCuu.DataSource = dts
        
    End Sub

    Private Sub CheckBoxTacGia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTacGia.CheckedChanged
        If (CheckBoxTacGia.Checked) Then
            txtTacGia.Enabled = True
        Else
            txtTacGia.Clear()
            txtTacGia.Enabled = False
        End If
    End Sub

    Private Sub CheckBoxTheLoai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTheLoai.CheckedChanged
        If (CheckBoxTheLoai.Checked) Then
            ComboBoxTheLoai.Enabled = True
        Else
            ComboBoxTheLoai.SelectedIndex = -1
            ComboBoxTheLoai.Enabled = False
        End If
    End Sub
End Class